package Practice;
//计算总成绩和平均成绩
import java.util.Scanner;

public class CalTotalAvg {
    public static void main(String[] args) {
        double[] scores = scores(6);
        double total = toal(scores);
        double avg = avg(scores);
        System.out.println("总分是:" + total);
        System.out.println("平均分是:" + avg);

    }

    //录入一个成绩
    public static double[] scores(int num) {
        Scanner scanner = new Scanner(System.in);
        double[] scores = new double[num];
        for (int i = 0; i < scores.length; i++) {
            System.out.println("第"+(i+1)+"个人的成绩是:");
            scores[i] = scanner.nextDouble();
        }
        return scores;
    }


    //计算总分
    public static double toal(double[] scores) {
        double t = 0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] > max) {
                max = scores[i];
            }
            if (scores[i] < min) {
                min = scores[i];
            }
            t += scores[i];
        }
        return t - max - min;
    }

    //计算平均分
    public static double avg(double[] scores) {
        double avg = 0.0;
        double total = toal(scores);
        avg = total / (scores.length - 2);
        return avg;

    }

}
